package mytest.com.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import javax.inject.Inject;

public class MainActivity extends AppCompatActivity {
    /*普通的用法*/
    @Inject
    Dog mDog;

    /*Cat类实现了@Singleton
    * 这个类的实例现在是全局单例模式*/
    @Inject
    Cat mCat1;

    @Inject
    Cat mCat2;

    /*带参数的构造方法*/
    @Inject
    Orange mOrange;


    /*带修饰符的方法*/
    @Inject
    @Type("normal")
    Milk mMilkNormal;

    @Inject
    @Type("custmize")
    Milk mMilkCus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /*a) 使用@Inject声明属性变量，表示注入这个依赖
          b) 调用xxxComponent的inject，注入依赖*/
//        AnimalsComponent animalsComponent=DaggerAnimalsComponent.create();
//        animalsComponent.inject(this);
        AnimalsComponent animalsComponent = DaggerAnimalsComponent.builder().
                animalsMoudle(new AnimalsMoudle(this)).build();
        animalsComponent.inject(this);

        mDog.showLog();
        mCat1.showLog();
        mOrange.showToast();

        Log.d("SingletonTest", "mCat1:" + mCat1);
        Log.d("SingletonTest", "mCat1:" + mCat2);

        Intent intent=new Intent(this,SecondActivity.class);
        startActivity(intent);

    }


}
